﻿using System;
using System.IO;
using Presentation;

namespace Infrastructure
{
    public class TextLogger : ILogger
    {
         public TextLogger(string logFileName)
        {
            LogFileName = logFileName;

            CreateLogFileIfNotExists();
        }

        private void CreateLogFileIfNotExists()
        {
            if (! File.Exists(@LogFileName))
            {
                var stream = File.Create(@LogFileName);
                stream.Close();
            }
        }

        #region ILogger Implementation
        public string LogFileName { set; private get; }

        public void AddLog(string log)
        {
            var writer = new StreamWriter(@LogFileName, true);

            try
            {
                writer.WriteLine(DateTime.Now + "\t" + log);
            }
            finally
            {
                writer.Close();
            }

        }

        public string[] GetLogs()
        {
            return File.ReadAllLines(@LogFileName);
        }
        #endregion
    }
}

